<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>补签申请</title>
</head>
<body>

<script type="text/javascript" src="./$.js"></script>
<script>
    require(['!this.js'], $$.load)
</script>
</body>
</html>


<!--tpl部分-->
<template data-name="this.htm">
    <div class="add" v-if="data" id="form">
        <a class="info" href="mylist.html">
            <img :src="data.avatar">
            <div class="rightinfo">
                <div class="infoperson">
                    <p>{{data.name}}</p>
                    <p>{{data.dept}}</p>
                </div>
                <div class="infowork">
                    <span>已补签</span>
                    <div class="num">{{data.count}}</div>
                    <span>最多补签</span>
                    <div class="num">5</div>
                </div>
            </div>
            <div class="addSangle"><img src="../$res/imgers/into.png"></div>
        </a>

        <div class="buqian_content">
            <div class="content">
                <div class="weui-cell__bd myweui-cell">
                    <input class="weui-input" type="datetime-local" value="" v-model="post.time" required emptyTips="请选择补签时间" placeholder="请选择补签时间" >
                    <img src="../$res/imgers/yanzheng_yes.png">
                </div>
                <div class="weui-cell__bd mytextarea">
                    <textarea class="weui-textarea" placeholder="请输入补签理由" rows="3" v-model="post.reason" required emptyTips="请输入补签理由"></textarea>
                    <div class="weui-textarea-counter">
                        <img src="../$res/imgers/yanzheng_yes.png">
                    </div>
                </div>
            </div>
        </div>
        <div class="weui-cells__title">请选择审批人</div>
        <div class="weui-cells weui-cells_checkbox">
            <label class="weui-cell weui-check__label" v-for="(value,index) in data.sp">
                <div class="weui-cell__hd">
                    <input type="radio" class="weui-check" name="checkbox1" :value='value.id' v-model="post.sp_uid" required emptyTips="请选择审批人">
                    <i class="weui-icon-checked"></i>
                </div>
                <div class="weui-cell__bd">
                    <p>{{value.name}}</p>
                </div>
            </label>
        </div>

        <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips" @click="add">提交补签申请</a>
        </div>
    </div>
</template>

<!--JS部分-->
<script data-name="this.js">

    function get_person_info() {
        $$.ajax({
            url: "/kaoqin/apply/supply",
            data: {},
            result: {
                $200: function (ret) {
                    weui.loading().hide();
                    $$.m.data = ret.data;
                    $.extend($$.m.post, {
                        name: $$.m.data.name,
                        avatar: $$.m.data.avatar,
                        dept: $$.m.data.dept,
                        mobile: $$.m.data.mobile
                    });
                }
            }
        });
    }

    /*由于从weui的input拿到的时间格式跟后台需要的格式不一样，故需要处理一下*/
    function set_time(val) {
        function addZero(myint) {
            var end;
            if (myint < 10) {
                end = '0' + myint;
                return end;
            } else {
                return myint;
            }
        }
        if(val==''){
            return '';
        }
        var time = new Date(val).getTime() - 28800000;
        var date = new Date(time);

        var year = date.getFullYear();
        var month = addZero(date.getMonth() + 1);
        var day = addZero(date.getDate());
        var hour = addZero(date.getHours());
        var minute = addZero(date.getMinutes());
        return '' + year + month + day + hour + minute;
    }

    require('../$res/js/common');
    module.exports = {
        template: require('!this.htm'),
        methods: {
            add: function () {
                weui.form.validate('#form', function (error) {
                    if (!error) {
                        weui.loading('提交中');

                        $$.m.post.time = set_time($$.m.post.time);
                        $$.ajax({
                            url: "/kaoqin/apply/add_supply",
                            data: $$.m.post,
                            result: {
                                $200: function () {
                                    weui.loading().hide();
                                    weui.toast('提交成功', function () {
                                        window.history.back();
                                    }, 500);
                                }
                            }
                        });
                    }
                });
                weui.form.checkIfBlur('#form', {});
            }
        },
        loaded: function () {
            $$.m = {
                data: false,
                post: {
                    time: '',
                    sp_uid: '',
                    reason: ''
                }
            };
            weui.loading('加载中');
        },
        mounted: function () {
            get_person_info();
        }
    };

</script>